home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 3 of 3.iso / chapte10 / getadcap / line.c < prev    next >
C/C++ Source or Header  |  1996-04-28  |  26KB  |  791 lines

  1.  
  2. #include <windows.h> 
  3. #include <windowsx.h> 
  4. #include "line.h" 
  5. #include "tapi.h"
  6.  
  7. #define BUFSIZE 256
  8. #define APIHIVERSION     0x00010028    /* 1.40 */
  9. #define APILOWVERSION    0x00010000    /* 1.0 */
  10. #define EXTHIVERSION     0x00010005    /* 1.5 */
  11. #define EXTLOWVERSION    0x00000009    /* 0.9 */ 
  12. #define OWNER        0
  13. #define MONITOR      1
  14. #define MAX_CALL        3
  15. #define MAX_LINE        2
  16.  
  17.  
  18. #if defined (WIN32)
  19.     #define IS_WIN32 TRUE
  20. #else
  21.     #define IS_WIN32 FALSE
  22. #endif
  23.  
  24. #define IS_NT      IS_WIN32 && (BOOL)(GetVersion() < 0x80000000)
  25. #define IS_WIN32S  IS_WIN32 && (BOOL)(!(IS_NT) && (LOBYTE(LOWORD(GetVersion()))<4))
  26. #define IS_WIN95   (BOOL)(!(IS_NT) && !(IS_WIN32S)) && IS_WIN32
  27.  
  28. LPCTSTR lpszAppName = "lineGetAddressCaps";
  29. LPCTSTR lpszTitle   = "lineGetAddressCaps"; 
  30.  
  31. HINSTANCE hInst;   // current instance
  32. HWND hWnd;         // parent window handle
  33. HWND hListWnd;     // listbox
  34. HDC  hdc;
  35. TEXTMETRIC  tm ;
  36.  
  37. BOOL RegisterWin95( CONST WNDCLASS* lpwc );
  38.  
  39.  
  40. int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
  41.                       LPTSTR lpCmdLine, int nCmdShow)
  42. {
  43.    MSG      msg;
  44.    WNDCLASS wc;
  45.  
  46.    wc.style         = CS_HREDRAW | CS_VREDRAW;
  47.    wc.lpfnWndProc   = (WNDPROC)WndProc;       
  48.    wc.cbClsExtra    = 0;                      
  49.    wc.cbWndExtra    = 0;                      
  50.    wc.hInstance     = hInstance;              
  51.    wc.hIcon         = LoadIcon (hInstance, lpszAppName); 
  52.    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  53.    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  54.    wc.lpszMenuName  = lpszAppName;              
  55.    wc.lpszClassName = lpszAppName;              
  56.  
  57.    if ( IS_WIN95 )
  58.    {
  59.       if ( !RegisterWin95( &wc ) )
  60.          return( FALSE );
  61.    }
  62.    else if ( !RegisterClass( &wc ) )
  63.       return( FALSE );
  64.  
  65.    hInst = hInstance; 
  66.  
  67.    hWnd = CreateWindow( lpszAppName, 
  68.                         lpszTitle,    
  69.                         WS_OVERLAPPEDWINDOW, 
  70.                         CW_USEDEFAULT, 0, 
  71.                         CW_USEDEFAULT, 0,  
  72.                         NULL,              
  73.                         NULL,              
  74.                         hInstance,         
  75.                         NULL               
  76.                       );
  77.  
  78.    if ( !hWnd ) 
  79.       return( FALSE );
  80.  
  81.    ShowWindow( hWnd, nCmdShow ); 
  82.    UpdateWindow( hWnd );         
  83.  
  84.    while( GetMessage( &msg, NULL, 0, 0) )   
  85.    {
  86.       TranslateMessage( &msg ); 
  87.       DispatchMessage( &msg );  
  88.    }
  89.  
  90.    return( msg.wParam ); 
  91. }
  92.  
  93.  
  94. BOOL RegisterWin95( CONST WNDCLASS* lpwc )
  95. {
  96.     WNDCLASSEX wcex;
  97.  
  98.    wcex.style         = lpwc->style;
  99.    wcex.lpfnWndProc   = lpwc->lpfnWndProc;
  100.    wcex.cbClsExtra    = lpwc->cbClsExtra;
  101.    wcex.cbWndExtra    = lpwc->cbWndExtra;
  102.    wcex.hInstance     = lpwc->hInstance;
  103.    wcex.hIcon         = lpwc->hIcon;
  104.    wcex.hCursor       = lpwc->hCursor;
  105.    wcex.hbrBackground = lpwc->hbrBackground;
  106.    wcex.lpszMenuName  = lpwc->lpszMenuName;
  107.    wcex.lpszClassName = lpwc->lpszClassName;
  108.  
  109.    // Added elements for Windows 95.
  110.    //...............................
  111.    wcex.cbSize = sizeof(WNDCLASSEX);
  112.    wcex.hIconSm = LoadImage(wcex.hInstance, lpwc->lpszClassName, 
  113.                             IMAGE_ICON, 16, 16,
  114.                             LR_DEFAULTCOLOR );
  115.             
  116.    return RegisterClassEx( &wcex );
  117. }
  118.  
  119. #define CONFCALL    1
  120. #define CONSULT      2
  121.  
  122. enum CallState
  123. {
  124.     Idle,
  125.     Offering,
  126.     Accepted,
  127.     Dialtone,
  128.     Dialing,
  129.     Ringback,
  130.     Busy,
  131.     Special,
  132.     Connected,
  133.     Proceeding,
  134.     Conferenced,
  135.     Onholdconf,
  136.     Disconnected,
  137.     Unknown
  138. };
  139.  
  140. typedef struct tagMYINFO      // general application information
  141. {
  142.     HLINEAPP lineApp;         // instance handle TAPI gives back to us                                                                              through lineInitialize()
  143.     DWORD dwNumDevices;       // number of available devices
  144.     DWORD dwAPIVersion;       // API version the line supports
  145.      DWORD dwExtVersion;           // extended version
  146.     char szLocation[128];     // location        
  147.      char szCallingCard[128];  // calling card being used
  148.     char szAreaCode[4];       // area code       
  149.     char szCountry[128];      // calling card being used
  150. } MYINFO;
  151.  
  152. typedef struct tagLINEINFO  // information on an open line
  153. {
  154.     DWORD dwNumAddress;     // number of available addresses on the line 
  155.     HLINE hLine;            // handle to the line as returned by lineOpen 
  156.      DWORD dwLineID;         // the line ID of this line
  157.     char  szLineName[128];  // the line's name 
  158.  
  159. } MYLINEINFO;
  160.  
  161. typedef struct tagMYCALLINFO  //information on a call                     
  162. {
  163.     
  164. DWORD       eCallState;    // TAPI's line call State, set as user-defined enums
  165. DWORD      dwRequestID;   // requestID returned by async TAPI functions lineMakeCall/lineDropCall
  166. DWORD      dwAddressID;   // the originating address ID of the call being made 
  167. LPCSTR     lpszAddress;    
  168. HLINE     hLine;         // handle to the line 
  169. HCALL        hCall;         // handle to the call 
  170.    
  171. char szDialString[TAPIMAXDESTADDRESSSIZE];  //phone number being dialed
  172. char szDialStringOriginal[TAPIMAXDESTADDRESSSIZE];
  173. char szDialStringCanonical[TAPIMAXDESTADDRESSSIZE];
  174. char szCalledParty[TAPIMAXCALLEDPARTYSIZE]; // name of the party
  175. DWORD dwTranslateResults;
  176.         
  177. } MYCALLINFO;
  178.  
  179. enum CallAction     // Declare enum type CallAction (used in lineSetAppSpecific)
  180. {
  181.    HOLD,            // hold the call
  182.    TRANSFER,        // transfer the call
  183.    REDIRECT,        // redirect the call
  184.    DROP,            // drop the call
  185.    PARK             // park the call
  186. }; 
  187.  
  188. MYINFO myInfo;          //instance of MYINFO structure
  189. MYLINEINFO myLineInfo[MAX_LINE];  //instance of MYLINEINFO structure
  190. MYCALLINFO myCallInfo[MAX_CALL]; //array of MYCALLINFO strcuture
  191.  
  192. LONG lRet;        //return code
  193. char buf[BUFSIZE];    // buffer for debug message
  194.  
  195. DWORD dwLineID = 0;
  196. DWORD i;
  197. LINEEXTENSIONID        ext_id;
  198. LINEDEVCAPS            *plineDevCaps;
  199. LINEADDRESSCAPS        *plineAddressCaps;
  200. LINEADDRESSSTATUS     *plineAddressStat;
  201. LINECALLINFO            *plineCallInfo;
  202. LINECALLSTATUS         *plineCallStatus;
  203. LINECALLLIST            *plineCallList;
  204. LINEDEVSTATUS           *plineDevStatus;
  205. LINETRANSLATECAPS       *plineTranslateCaps;
  206. LINETRANSLATEOUTPUT  *plineTranslateOutput;
  207. LINECALLPARAMS           *plineCallParams;
  208. LINEDEVSTATUS           *plineDevStatus;
  209. LINEFORWARDLIST        *plineForwardList;
  210. LINETRANSLATECAPS       *plineTranslateCaps;
  211. LINEREQMAKECALL       lineReqMakeCall;
  212. VARSTRING               *pDeviceConfig;
  213. VARSTRING               *pDeviceId;
  214. VARSTRING               *pNonDirAddress;
  215.  
  216. LPLINELOCATIONENTRY  lineLocEntry;
  217. LPLINECARDENTRY        lineCardEntry;
  218. LINECOUNTRYLIST         *plineCountryList;
  219. LPLINECOUNTRYENTRY   lineCE;
  220.  
  221. LPSTR                lpData;
  222.  
  223. HICON                hIcon = NULL;        //used in lineGetID();
  224. DWORD                dwNumRings;    //used in lineGetNumRings();
  225. HCALL                hConsultCall; //handle to consultation linePrepareAddToConference, SetupConference
  226. HCALL                hConfCall; //handle to consultation linePrepareAddToConference, SetupConference   
  227. HCALL                hParkedCall;
  228.  
  229. DWORD                dwCompletionID;  //used in lineCompleteCall()
  230.  
  231. char                szName[128];
  232. char                szNumber[128];
  233. char                szDigits[128];
  234. char                szDevConfig[128];
  235.  
  236. LONG lRet;
  237. char buf[BUFSIZE];
  238.  
  239. LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  240. {
  241.    switch( uMsg )
  242.    {
  243.       case WM_COMMAND :
  244.          switch( LOWORD( wParam ) )
  245.          {
  246.             case IDM_RUN :
  247.                DialogBox( hInst, "IDD_DIALNUM", hWnd, (DLGPROC)Dial );
  248.                break;
  249.  
  250.             case IDM_GETADDCAPS :
  251.                //query address caps only if we have a connected call
  252.                //................................................      
  253.                if (myCallInfo[0].eCallState != Connected)
  254.                {
  255.                   MessageBox (hWnd, "Place your call in the connected state and try again...", "", MB_OK);
  256.                   break;
  257.                }
  258.  
  259.                //allocate buffer for the LINEADDRESSCAPS structure 
  260.                //...................................................
  261.                plineAddressCaps = (LINEADDRESSCAPS *) calloc (1, 
  262.                                      sizeof(LINEADDRESSCAPS) +1000);
  263.                plineAddressCaps->dwTotalSize = sizeof(LINEADDRESSCAPS) +                            
  264.                                                      1000;
  265.                   
  266.                // get address capability info
  267.                //..................................
  268.                lRet = lineGetAddressCaps(myInfo.lineApp, myLineInfo[0].dwLineID,   
  269.                                  myCallInfo[0].dwAddressID, myInfo.dwAPIVersion, 0 
  270.                                  ,plineAddressCaps);
  271.                   
  272.                if (lRet == 0)
  273.                {
  274.                   wsprintf (buf, "lineGetAddressCaps succeeded!");
  275.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  276.                   wsprintf( buf,"The Line Device ID is: x%lx", plineAddressCaps->dwLineDeviceID);
  277.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  278.                   wsprintf( buf,"The Address Sharing mode is: x%lx", plineAddressCaps->dwAddressSharing);
  279.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  280.                   wsprintf( buf,"The Address States are: x%lx", plineAddressCaps->dwAddressStates);
  281.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  282.                   wsprintf( buf,"The Call Info States are: x%lx", plineAddressCaps->dwCallInfoStates);
  283.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  284.                   wsprintf( buf,"The Call States are: x%lx", plineAddressCaps->dwCallStates);
  285.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  286.                }
  287.                else 
  288.                {
  289.                   wsprintf ( buf,"lineGetAddressCaps failed, err=x%lx",lRet);
  290.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  291.                   lineError(lRet);
  292.                }
  293.                
  294.                free(plineAddressCaps);
  295.                break;   
  296.             
  297.             case IDM_ABOUT :
  298.             {
  299.                 DialogBox( hInst, "AboutBox", hWnd, (DLGPROC)About );
  300.                break;
  301.             }
  302.  
  303.             case IDM_EXIT :
  304.             {
  305.                for (i = 0; i < myInfo.dwNumDevices; i++)
  306.                        lineClose(myLineInfo[i].hLine);
  307.                     lineShutdown(myInfo.lineApp);
  308.                DestroyWindow( hWnd );
  309.                break;
  310.             }
  311.             }                  
  312.                  
  313.          break;
  314.  
  315.       case WM_CREATE :
  316.       {
  317.          hdc = GetDC (hWnd) ;
  318.          GetTextMetrics (hdc, &tm) ;
  319.          ReleaseDC (hWnd, hdc) ;
  320.  
  321.          hListWnd = CreateWindowEx( 0, "listbox", 
  322.                         " ",    
  323.                         WS_CHILD | WS_VISIBLE,  
  324.                         tm.tmAveCharWidth, tm.tmHeight * 3, 
  325.                         tm.tmAveCharWidth * 16 +
  326.                                    GetSystemMetrics (SM_CXVSCROLL), 
  327.                         tm.tmHeight * 5,  
  328.                         hWnd,              
  329.                         NULL,              
  330.                         hInst,         
  331.                         NULL               
  332.                         );
  333.  
  334.          
  335.          //lineInitialize
  336.             //...............................................
  337.          lRet = lineInitialize(&myInfo.lineApp, hInst, lineCallback, NULL, &myInfo.dwNumDevices);
  338.          if (lRet == 0) 
  339.          {
  340.             wsprintf (buf, "lineInitialize suceeded!");
  341.               SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  342.            }
  343.          else 
  344.           {
  345.                wsprintf ( buf,"lineInitialize failed, err=x%lx",lRet);
  346.                SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  347.                lineError(lRet);
  348.                break;
  349.          }                    
  350.          
  351.          //lineNegotiateAPIVersion
  352.           //...............................................
  353.          lRet = lineNegotiateAPIVersion(myInfo.lineApp, 0, APILOWVERSION, APIHIVERSION, 
  354.                                            &myInfo.dwAPIVersion, &ext_id);
  355.          if (lRet == 0)                        
  356.          {
  357.             wsprintf (buf, "lineNegotiateAPIVersion suceeded!");
  358.               SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  359.          }
  360.          else 
  361.           {
  362.                wsprintf (buf, "lineNegotiateAPIVersion failed, err=x%lx",
  363.                            lRet);
  364.                SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  365.                lineError(lRet);
  366.                lineShutdown (myInfo.lineApp);
  367.             break;
  368.          }
  369.  
  370.           //lineNegotiateExtVersion
  371.           //...............................................
  372.          lRet = lineNegotiateExtVersion(myInfo.lineApp, 0, myInfo.dwAPIVersion, EXTLOWVERSION, 
  373.                                            EXTHIVERSION, &myInfo.dwExtVersion);
  374.          if (lRet == 0)                        
  375.          {
  376.             wsprintf (buf, "lineNegotiateExtVersion suceeded!");
  377.             SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  378.  
  379.          }
  380.           else 
  381.           {
  382.                wsprintf (buf, "lineNegotiateExtVersion failed, err=x%lx",
  383.                      lRet);
  384.               SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  385.               lineError(lRet);
  386.       
  387.          }
  388.  
  389.           //lineGetDevCaps
  390.           //for each line device, get capabilities until we find one that supports
  391.          //interactive voice 
  392.           //...............................................
  393.          plineDevCaps = (LINEDEVCAPS *) calloc (1, sizeof(LINEDEVCAPS)+1000);
  394.          plineDevCaps->dwTotalSize = sizeof(LINEDEVCAPS) + 1000;
  395.          for (i = 0; i < myInfo.dwNumDevices; i++)
  396.          {
  397.             lineGetDevCaps(myInfo.lineApp, i, myInfo.dwAPIVersion, 0, plineDevCaps);
  398.             if (plineDevCaps->dwMediaModes & LINEMEDIAMODE_INTERACTIVEVOICE) 
  399.             {
  400.                
  401.                myLineInfo[i].dwNumAddress = plineDevCaps->dwNumAddresses;
  402.                   myLineInfo[i].dwLineID = i;
  403.                    if (plineDevCaps->dwLineNameSize > 0)
  404.                           strcpy(myLineInfo[i].szLineName,((LPSTR)(plineDevCaps)+plineDevCaps->dwLineNameOffset));
  405.              }
  406.           }
  407.  
  408.          //lineOpen
  409.           //................................................................
  410.           lRet = lineOpen(myInfo.lineApp,myLineInfo[OWNER].dwLineID,&myLineInfo[OWNER].hLine,
  411.                            myInfo.dwAPIVersion,0,(DWORD)lineCallback, LINECALLPRIVILEGE_NONE,
  412.                             LINEMEDIAMODE_DATAMODEM, NULL);
  413.           if (lRet == 0)
  414.           {
  415.             wsprintf (buf, "lineOpen suceeded!");
  416.             SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;         }
  417.            else 
  418.            {
  419.                wsprintf ( buf,"lineOpen failed, err=x%lx", lRet);
  420.                SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  421.                lineError(lRet);
  422.           }
  423.        
  424.          break;
  425.       }
  426.       
  427.       case WM_SIZE:
  428.           MoveWindow(hListWnd,0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
  429.          break;
  430.  
  431.       case WM_DESTROY :
  432.               PostQuitMessage(0);
  433.               break;
  434.  
  435.       default :
  436.             return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
  437.    }
  438.  
  439.    return( 0L );
  440. }
  441.  
  442.  
  443.  
  444.  
  445. /****************************************************************************
  446.     FUNCTION: lineCallback
  447.     PURPOSE:  callback function handles line events
  448. ****************************************************************************/
  449. LRESULT CALLBACK lineCallback (DWORD dwDevice, DWORD dwMsg,
  450.                                        DWORD dwCallbackInst, DWORD dwParam1,
  451.                                        DWORD dwParam2,DWORD dwParam3)
  452. {
  453.    switch (dwMsg)
  454.    {
  455.       case LINE_CALLSTATE:
  456.        {
  457.             for (i = 0; i < MAX_CALL; i++)
  458.            {
  459.                 if (dwDevice = (DWORD) myCallInfo[i].hCall) 
  460.                  switch (dwParam1)
  461.                  {
  462.                     case LINECALLSTATE_IDLE:
  463.                         myCallInfo[i].eCallState = Idle;
  464.                   break;
  465.                     
  466.                     case LINECALLSTATE_OFFERING:
  467.                   myCallInfo[i].eCallState = Offering;
  468.                   break;
  469.                                    
  470.                     case LINECALLSTATE_ACCEPTED:
  471.                         myCallInfo[i].eCallState = Accepted;
  472.                         break;
  473.                     
  474.                     case LINECALLSTATE_DIALTONE:
  475.                         myCallInfo[i].eCallState = Dialtone;
  476.                   break;
  477.                     
  478.                     case LINECALLSTATE_DIALING:
  479.                         myCallInfo[i].eCallState = Dialing;
  480.                         break;
  481.                   
  482.                   case LINECALLSTATE_RINGBACK:
  483.                         myCallInfo[i].eCallState = Ringback;
  484.                         break;
  485.             
  486.                     case LINECALLSTATE_BUSY:
  487.                         myCallInfo[i].eCallState = Busy;
  488.                         break;
  489.             
  490.                     case LINECALLSTATE_SPECIALINFO:
  491.                         myCallInfo[i].eCallState = Special;
  492.                        break;
  493.             
  494.                     case LINECALLSTATE_CONNECTED:
  495.                        myCallInfo[i].eCallState = Connected;
  496.                   break;
  497.  
  498.                     case LINECALLSTATE_PROCEEDING:
  499.                         myCallInfo[i].eCallState = Proceeding;
  500.                        break;
  501.             
  502.                     case LINECALLSTATE_CONFERENCED:
  503.                         myCallInfo[i].eCallState = Conferenced;
  504.                        break;
  505.             
  506.                     case LINECALLSTATE_ONHOLDPENDCONF:
  507.                         break;
  508.                 
  509.                case LINECALLSTATE_DISCONNECTED:
  510.                         myCallInfo[i].eCallState = Disconnected;
  511.                        break;
  512.             
  513.                     case LINECALLSTATE_UNKNOWN:
  514.                         myCallInfo[i].eCallState = Unknown;
  515.                        break;
  516.        
  517.              }
  518.           }
  519.        }
  520.  
  521.        case LINE_MONITORMEDIA:
  522.            break;
  523.  
  524.        case LINE_MONITORDIGITS:
  525.           break;
  526.  
  527.          case LINE_MONITORTONE:
  528.           break;
  529.    
  530.        //error handling for functions completed asynchronously
  531.         //.....................................................
  532.        case LINE_REPLY:
  533.         {
  534.             for (i = 0; i < MAX_CALL; i++)
  535.            {
  536.                 if (dwParam1 = myCallInfo[i].dwRequestID)
  537.                {
  538.                    if (dwParam2 != 0)
  539.                    {
  540.                        lineError((LONG) dwParam2);
  541.                        break;
  542.                    }
  543.                }
  544.            }
  545.         break;
  546.         }
  547.  
  548.         case LINE_GENERATE:
  549.           break;
  550.      
  551.        case LINE_REQUEST:
  552.          break;
  553.  
  554.         case LINE_GATHERDIGITS:
  555.            break;
  556.    }
  557.  
  558.    return (TRUE);
  559.  
  560.  
  561. /****************************************************************************
  562.     FUNCTION: lineError
  563.     PURPOSE:  line error messages
  564. ****************************************************************************/
  565. void lineError (LONG lrc)
  566. {
  567.  switch (lrc) {
  568.     case LINEERR_INVALAPPHANDLE:
  569.        MessageBox (hWnd, "Invalid app handle.", "", MB_OK);
  570.        break;
  571.     case LINEERR_BADDEVICEID:
  572.        MessageBox (hWnd,"The specified line device ID is out of range.", "", 
  573.                    MB_OK);
  574.        break;
  575.     case LINEERR_INCOMPATIBLEAPIVERSION:
  576.        MessageBox (hWnd, "Incompatible API version.", "", MB_OK);
  577.        break;
  578.     
  579.     case LINEERR_ADDRESSBLOCKED:
  580.        MessageBox (hWnd, "Address was blocked.", "", MB_OK);
  581.        break;
  582.  
  583.     case LINEERR_BEARERMODEUNAVAIL:
  584.        MessageBox (hWnd, "Bearer Mode Unavailable.", "", MB_OK);
  585.        break;
  586.  
  587.     case LINEERR_CALLUNAVAIL:
  588.        MessageBox (hWnd, "Call appearances in use..", "", MB_OK);
  589.        break;
  590.  
  591.     case LINEERR_INUSE:
  592.        MessageBox (hWnd, "Line in Use.", "", MB_OK);
  593.        break;
  594.     
  595.     case LINEERR_INVALADDRESS:
  596.        MessageBox (hWnd, "Invalid Address.", "", MB_OK);
  597.        break;
  598.  
  599.     case LINEERR_INVALADDRESSID:
  600.        MessageBox (hWnd, "Invalid Address ID.", "", MB_OK);
  601.        break;
  602.  
  603.     case LINEERR_INVALCALLPARAMS:
  604.        MessageBox (hWnd, "Invalid Address ID.", "", MB_OK);
  605.        break;
  606.      
  607.     case LINEERR_INCOMPATIBLEEXTVERSION:
  608.        MessageBox (hWnd, "Incompatible extension version.","", MB_OK);
  609.        break;
  610.     case LINEERR_NOMEM:
  611.        MessageBox (hWnd, "No memory","", MB_OK);
  612.        break;
  613.     case LINEERR_NODRIVER:
  614.        MessageBox (hWnd, "No driver loaded", "", MB_OK);
  615.        break;
  616.     case LINEERR_RESOURCEUNAVAIL:
  617.        MessageBox (hWnd, "Resource overcommittment", "", MB_OK);
  618.        break;
  619.     case LINEERR_INVALPRIVSELECT:
  620.        MessageBox (hWnd, "Requested invalid priviledges", "", MB_OK);
  621.        break;
  622.     case LINEERR_INVALMEDIAMODE:
  623.        MessageBox (hWnd, "Requested invalid media mode", "", MB_OK);
  624.        break;
  625.     case LINEERR_LINEMAPPERFAILED:
  626.        MessageBox (hWnd, "Line mapper failed", "", MB_OK);
  627.        break;
  628.     case LINEERR_INVALPOINTER:
  629.        MessageBox (hWnd, "The specified pointer parameter is invalid.",
  630.                    "", MB_OK);
  631.        break;
  632.     case LINEERR_OPERATIONFAILED:
  633.        MessageBox (hWnd, "Operation failed.", "", MB_OK);
  634.        break;
  635.     case LINEERR_INVALLINEHANDLE:
  636.        MessageBox (hWnd, "Invalid line handle", "", MB_OK);
  637.        break;
  638.     case LINEERR_INVALCALLHANDLE:
  639.        MessageBox (hWnd, "Invalid call handle", "", MB_OK);
  640.        break;
  641.     case LINEERR_INVALCALLSELECT:
  642.        MessageBox (hWnd, "Invalid call selection", "", MB_OK);
  643.        break;
  644.     case LINEERR_NODEVICE:
  645.        MessageBox (hWnd, "No associated device for given class",
  646.                    "", MB_OK);
  647.        break;
  648.     case LINEERR_OPERATIONUNAVAIL:
  649.        MessageBox (hWnd, "The operation is unavailable",
  650.                    "", MB_OK);
  651.        break;
  652.     case LINEERR_INVALPARAM:
  653.         MessageBox(hWnd, "Invalid Paramater", "", MB_OK);
  654.        break; 
  655.  
  656.     case LINEERR_TARGETNOTFOUND:
  657.         MessageBox(hWnd, "Target Not Found", "", MB_OK);
  658.        break; 
  659.  
  660.    case LINEERR_NOREQUEST:
  661.       MessageBox(hWnd, "No outstanding Assisted Telephony requests.", "", MB_OK);
  662.        break; 
  663.    }
  664. }
  665.  
  666. LRESULT CALLBACK Dial ( HWND hDlg,           // window handle of the dialog box
  667.                         UINT message,        // type of message
  668.                         WPARAM wParam,       // message-specific information
  669.                         LPARAM lParam)
  670. {
  671.    switch (message) 
  672.    {
  673.        case WM_INITDIALOG:  // message: initialize dialog box
  674.                return (TRUE);
  675.  
  676.        case WM_COMMAND:                              // message: received a command
  677.          if (   LOWORD(wParam) == IDOK )        // "OK" box selected?
  678.          {
  679.             GetDlgItemText(hDlg, IDC_NAME, szName, 128);
  680.                 GetDlgItemText(hDlg, IDC_NUMBER, szNumber, 128);
  681.                                       
  682.  
  683.                 // put up a dialog box to obtain a string to dial from the user
  684.                //...........................................................
  685.                strcpy(myCallInfo[0].szDialStringOriginal, szNumber); 
  686.                
  687.                //allocate buffer for the LINEADDRESSCAPS strucuture 
  688.                //...................................................
  689.                plineTranslateOutput = (LINETRANSLATEOUTPUT *) calloc (1, sizeof(LINETRANSLATEOUTPUT)+1000);
  690.             plineTranslateOutput->dwTotalSize = sizeof(LINETRANSLATEOUTPUT) + 1000;
  691.               
  692.                // translate the Address to a dialable address and Canonical address
  693.                //.....................................................................
  694.                lRet = lineTranslateAddress(myInfo.lineApp, myLineInfo[OWNER].dwLineID, myInfo.dwAPIVersion,
  695.                                            myCallInfo[0].szDialStringOriginal, 0, 0, plineTranslateOutput);
  696.                               
  697.                if (lRet == 0)
  698.                {
  699.                        
  700.                    strncpy(myCallInfo[0].szDialString, (LPSTR)(plineTranslateOutput)
  701.                             + plineTranslateOutput->dwDialableStringOffset,
  702.                              plineTranslateOutput->dwDialableStringSize); 
  703.     
  704.                     strncpy(myCallInfo[0].szDialStringCanonical,(LPSTR)(plineTranslateOutput) 
  705.                             + plineTranslateOutput->dwDisplayableStringOffset,
  706.                             plineTranslateOutput->dwDisplayableStringSize); 
  707.                                            
  708.                    myCallInfo[0].dwTranslateResults = plineTranslateOutput->dwTranslateResults;
  709.                 }
  710.  
  711.                else 
  712.                {
  713.                     wsprintf ( buf,"lineTranslateAddress failed, err=x%lx", lRet);
  714.                     lineError(lRet);
  715.                    break;
  716.             }
  717.            
  718.                //lineMakeCall
  719.                //................................................................
  720.                           
  721.                plineCallParams = (LINECALLPARAMS *) calloc (1, sizeof(LINECALLPARAMS)+1000);
  722.             plineCallParams->dwTotalSize = sizeof(LINECALLPARAMS) + 1000;
  723.  
  724.                plineCallParams->dwBearerMode = LINEBEARERMODE_VOICE;
  725.                plineCallParams->dwMediaMode =  LINEMEDIAMODE_DATAMODEM;
  726.                plineCallParams->dwCallParamFlags = LINECALLPARAMFLAGS_IDLE;
  727.                plineCallParams->dwAddressMode    = LINEADDRESSMODE_ADDRESSID;
  728.                plineCallParams->dwAddressID    = 0;
  729.                plineCallParams->dwMinRate    = 1200;
  730.                plineCallParams->dwMaxRate    = 2400;
  731.                             
  732.                lRet = lineMakeCall(myLineInfo[OWNER].hLine,&myCallInfo[0].hCall, 
  733.                                       myCallInfo[0].szDialString ,0,  plineCallParams);
  734.            
  735.             if (lRet > 0)
  736.                {
  737.                wsprintf (buf, "lineMakeCall suceeded!");
  738.                SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;               
  739.                    myCallInfo[0].dwRequestID = lRet;
  740.                 }
  741.             else 
  742.                {
  743.                    wsprintf ( buf,"lineMakeCall failed, err=x%lx", lRet);
  744.                     lineError(lRet);
  745.                    break;
  746.             }
  747.             
  748.             EndDialog(hDlg, TRUE);        // Exit the dialog
  749.             return (TRUE);
  750.          }
  751.  
  752.             if (   LOWORD(wParam) == IDCANCEL)         // "OK" box selected?
  753.          {
  754.             EndDialog(hDlg, TRUE);        // Exit the dialog
  755.             return (TRUE);
  756.          }
  757.          break;
  758.  
  759.  
  760.    }
  761.  
  762.    return (FALSE); 
  763. }
  764.  
  765.  
  766. LRESULT CALLBACK About( HWND hDlg,           
  767.                         UINT message,        
  768.                         WPARAM wParam,       
  769.                         LPARAM lParam)
  770. {
  771.    switch (message) 
  772.    {
  773.        case WM_INITDIALOG: 
  774.                return (TRUE);
  775.  
  776.        case WM_COMMAND:                              
  777.                if (   LOWORD(wParam) == IDOK         
  778.                    || LOWORD(wParam) == IDCANCEL)    
  779.                {
  780.                        EndDialog(hDlg, TRUE);        
  781.                        return (TRUE);
  782.                }
  783.                break;
  784.    }
  785.  
  786.    return (FALSE); 
  787. }
  788.  
  789.  
  790.